package test1;

import test1.pojo.User;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;


/**
 * 根据name去重
 */
public class EntityDistinct {
    public static void main(String[] args) {

        List<User> list = new ArrayList<>();
        list.add(new User("张三",12));
        list.add(new User("李四",7));
        list.add(new User("小六",6));
        list.add(new User("小六",4));
        list.add(new User("王五",17));
        list.add(new User("王五",19));
        list.add(new User("xiaozhang",null));
        test1(list);
    }

    private static void test1(List<User> list){
        ArrayList<User> collect = list.stream()
                .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(User::getName))), ArrayList::new));
        collect.forEach(System.out::println);
    }
}
